<?php

defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$membersinfo=pdo_get('jy_jdpm_member',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']));
$return=array();
$return['channel'] = $_SESSION['channel'];
if($_RQ['op']=='main'){
	$membersinfo=pdo_get('jy_jdpm_member',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']));
	if($membersinfo['idcard_check']!=2){
		exi('请先实名认证','error','/member.safety/idcard');
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 1;
	$total='';
	$info=pdo_getslice('jy_jdpm_member_pledge_take',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']),array($pindex,$psize),$total,'','','createtime desc');
	$return['info'] = $info[0];
	$return['info']['remark']='';
	$return['info']['money']= number_format($membersinfo['wallet_pledge']-$membersinfo['wallet_pledge_freeze'],2,'.','');
	$return['info']['mission']=FatMoney2(round((($return['info']['money'] * 0.007) + 1) , 2));
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	if(!$postdata['money']){
		exi('请输入提现金额','error');
	}
	if(!$postdata['name']){
		exi('请输入账户姓名','error');
	}
	if(!$postdata['bank']){
		exi('请输入开户银行','error');
	}
	if(!$postdata['account']){
		exi('请输入正确的银行账号','error');
	}
	if(!$postdata['phone'] ||  strlen($postdata['phone'])!=11){
		exi('请输入正确的手机号码','error');
	}
	$money=round($postdata['money'],2);
	$marge=round((($money * 0.007) + 1),2);
	$postdata['mid']=$_SESSION['uid'];
	$postdata['createtime']=time();
	$postdata['mission']=$marge;
	if(($membersinfo['wallet_pledge']-$membersinfo['wallet_pledge_freeze'])<($money+$marge)){
		exi('输入金额大于可提现金额(含手续费)','error');
	}
	
	//$usable=$membersinfo['wallet_pledge']-$membersinfo['wallet_pledge_freeze']-$money-$marge;
	$freeze=$money+$marge;
	$mlog=array(
			
                        'mid'          => $_SESSION['uid'],
                        'money'        => $freeze ,
                        'channel'      => 2 ,
                        'create_time'  => time() ,
                        'update_time'  => time() ,
                        'auction_time' => 0 ,
                        'remarks'      => '提现金额冻结' ,
						'role'         => '',
                        'type'         => 12 ,
						'uniacid'=>$_SESSION['uniacid'],
                       
	);
	$pledgedata=array(
                        'mid'          => $_SESSION['uid'],
                        'money'        => $money,
                        'paytype'      => $postdata['paytype'],
                        'bank'      => $postdata['bank'],
						'bankhome'      => $postdata['bankhome'],
						'wechat'      => $postdata['wechat'],
						'alipay'      => $postdata['alipay'],
						'name'      => $postdata['name'],
						'account'      => $postdata['account'],
						'remark'      => $postdata['remark'],
						'address'      => $postdata['address'],
						'phone'      => $postdata['phone'],
						'type'      => $postdata['type'],
						'mission'      => $postdata['mission'],
						'createtime'=>time(),
						'uniacid'=>$_SESSION['uniacid'],
	);
	pdo_insert('jy_jdpm_money_log',$mlog);
	pdo_insert('jy_jdpm_member_pledge_take',$pledgedata);
	$tid =pdo_insertid();
	$userlog=array(
			
                        'mid'          => $_SESSION['uid'],
						'id'      => $tid,
                        'pledge'        => $freeze ,
                        'createtime'  => time() ,
                        'status' => 0 ,
                        'remarks'      => '提现金额冻结' , 
						'uniacid'=>$_SESSION['uniacid'],
	);
	pdo_insert('jy_jdpm_freezelog',$userlog);
	pdo_update('jy_jdpm_member',array('wallet_pledge_freeze +='=>$freeze),array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']));
	exi('已申请提现','','/member.wallettake/');
}

if($_RQ['op']=='getcharge'){
	$money=$_RQ['money'];
	$money = $money * 0.007 + 1;
	$return['charge']=round($money, 2);
	exi($return);
}
?>